<template>
	<view class="container pb115 ">
		<view class="main ">
			<view class="bf bs10 mainc ">
				<view class="p03 ">
					<view class="p30 f32 wei t-c ">{{(isbj?'修改':'填写')+'个人资料'}}</view>
					<view class="mb30 f24 c6 ">*请提供正确的个人资料与联系方式，以便获得最新会员优惠信息</view>
				</view>
				<mg-input ht="姓名" hw="130" isr="1" pr="请输入姓名" v-model="params.realName" vueId="5b591ef8-1"
					v-if='vipset.register.includes("USER_FORM_INFO_FLAG_NAME")'>
				</mg-input>
				<mg-input ht="电话" hw="130" isr="1" :max="11" pr="请输入手机号" t="number" v-model="params.userTel" vueId="5b591ef8-2"
					:vueSlots="['ft']" v-if='vipset.register.includes("USER_FORM_INFO_FLAG_MOBILE")'>
					<sq-btn @refresh="setTel" cname="text-btnf f24 ml20 p0 b00" h="50" slot="ft" t="自动填写" type="2"
						:vueId="'5b591ef8-3'+','+'5b591ef8-2'" w="120"></sq-btn>
				</mg-input>
				<mg-cell cname="p03" ht="性别" hw="130" isr="1" vueId="5b591ef8-4" :vueSlots="['bd']"
					v-if='vipset.register.includes("USER_FORM_INFO_FLAG_SEX")'>
					<view slot="bd">
						<mg-radio :arr="sexArr" color="#07C160" v-model="params.sex" :vueId="'5b591ef8-5'+','+'5b591ef8-4'"></mg-radio>
					</view>
				</mg-cell>
				<block v-if='vipset.register.includes("USER_FORM_INFO_FLAG_BIRTHDAY")'>
					<mg-cell ht="生日" hw="130" isr="1" last="1" vueId="5b591ef8-6" :vueSlots="['bd']" v-if="!isbj">
						<picker @change="bindDateChange" :end="endDate" mode="date" slot="bd" :value="date">
							<view class="c6 ">{{date}}</view>
						</picker>
					</mg-cell>
					<mg-cell :btt="date" bttc="c9" ht="生日" hw="130" isr="1" last="1" vueId="5b591ef8-7" v-else></mg-cell>
				</block>
				<view class="p13 f24 c9 ">*温馨提示：生日时间一旦保存后，将不能再次修改哦！</view>
			</view>
		</view>
		<view class="foot-btnc posi-r mt30 ">
			<button @tap="save" class="foot-btn b00 bs15 " :disabled="loading" hoverClass="btnhc" :loading="loading">提交</button>
		</view>
	</view>
</template>

<script>
	import bkB from "components/common/block-b.vue";
	import MgCell from "components/common/mg-cell.vue";
	import sqBtn from "components/common/sq-btn.vue";
	import mgInput from "components/form/mg-input.vue";
	import mgRadio from "components/form/mg-radio.vue";
	import {
		mapActions,
		mapState,
	} from 'vuex'
	import {
		utilMixins
	} from 'common/utilMixins';
	import {
		dateToTime,
		isFailParams,
		isTelCode,
		setNT,
		swnb,
		timeToDate
	} from 'common/util';
	export default {
		components: {
			mgInput,
			mgRadio,
			MgCell,
			bkB,
			sqBtn,
		},
		data: function() {
			return {
				t: "digit",
				params: {
					userTel: "",
					birthday: "",
					sex: "男",
					realName: ""
				},
				sexArr: [{
					value: "男",
					name: "男"
				}, {
					value: "女",
					name: "女",
					checked: "true"
				}],
				loading: !1,
				isEdit: !1,
				date: "",
				endDate: "",
				isbj: !1
			}
		},
		onLoad: function(e) {
			var t = this;
			e.userId && (t.isbj = !0), t.getSystem().then((function(e) {
				setNT("".concat(t.vipset.title || '会员', "-").concat(t.isbj ? "修改资料" : "提交资料"))
			})), t.date = t.endDate = timeToDate(dateToTime(), "yyyy-MM-dd"), t.getLoginInfo().then((
				function() {
					t.params.userTel = t.user.userTel || "", t.isbj && (t.params.realName = t.user.realName, t
						.params.sex = t.user.sex, t.date = timeToDate(t.user.birthday, "yyyy-MM-dd"))
				}));
		},
		mixins: [utilMixins],
		computed: {
			...mapState({
				vipset: function(e) {
					console.log('e: ', e);
					if(e.config.vipset && !e.config.vipset.register)e.config.vipset.register = [];
					return e.config.vipset
				}
			})
		},
		methods: {
			setTel: function(e) {
				this.params.userTel = e
			},
			bindDateChange: function(e) {
				this.date = e.target.value
			},
			save: function() {
				var e = this;
				var n, a, u;
				try {
					e.params.birthday = dateToTime(e.date),
					 n = [],
					  e.vipset.register.includes(
						"USER_FORM_INFO_FLAG_NAME") || n.push("realName"), e.vipset.register.includes(
						"USER_FORM_INFO_FLAG_SEX") || n.push("sex"), e.vipset.register.includes(
						"USER_FORM_INFO_FLAG_BIRTHDAY") || n.push("birthday"), a = isFailParams({
						field: e.params,
						filter: n,
						tips: {
							realName: "请输入姓名",
							userTel: "请输入手机号",
							birthday: "请选择生日"
						}
					});
				} catch (error) {

				}
				if (a) {
					if (isTelCode(e.params.userTel)) return message("请输入正确的手机号", 3);
					e.requestSM("vip");
					if (!e.isbj) {
						this.$api['vip-card_receive__card'](e.params).then(res => {
							e.refreshUser({
								nomask: 1,
								get: 1,
								now: 1
							}), swnb(1e3)
						})
					}
					// request({
					// 	url: e.api[e.isbj ? "SaveUser" : "hykk"],
					// 	method: "POST",
					// 	mask: 1,
					// 	data: e.params
					// });
				}
			}
		}
	}
</script>

<style scoped>
	.main {
		padding: 90rpx 40rpx 30rpx;
	}

	.mainc {
		padding: 20rpx 0 30rpx;
		box-shadow: 0rpx 10rpx 15rpx 5rpx hsla(0, 0%, 86.7%, .8);
	}
</style>